﻿namespace ExamV5.OnLineInter
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class LookResult : Page
    {
        protected GridView DataGridInfo;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private int int_0 = 0;
        protected Label labDCUser;
        protected Label labDCUserCode;
        protected Label labEndTime;
        protected Label labIsAnyUser;
        protected Label labIsIP;
        protected Label labIsLook;
        protected Label labTitleInfo;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        protected UpdatePanel UPPart;

        protected void DataGridInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label label5 = (Label)e.Row.Cells[0].FindControl("labItemInfo");
                Label label4 = (Label)e.Row.Cells[0].FindControl("labItemTitle");
                Label label3 = (Label)e.Row.Cells[0].FindControl("labIsSing");
                Label label = (Label)e.Row.Cells[0].FindControl("labItemCount");
                Label label2 = (Label)e.Row.Cells[0].FindControl("labID");
                TextBox box1 = (TextBox)e.Row.Cells[0].FindControl("txtWrite");
                string values = this.publicFun_0.GetValues(string.Concat(new object[] { "select count(*) as DCCount from QuestUser where DCID=", this.int_0, " and ItemID=", label2.Text }), "DCCount");
                if (values.Trim() == "")
                {
                    values = "0";
                }
                label4.Text = label4.Text + "&nbsp;&nbsp;<b>(共:" + values + "票)</b>";
                if (label3.Text == "Z")
                {
                    label.Text = "<table style='BORDER-COLLAPSE: collapse' borderColor='#cccccc' cellSpacing='0' borderColorDark='#cccccc' cellPadding='0' width='100%' border='1'>";
                    SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                    connection.Open();
                    SqlCommand command = new SqlCommand(string.Concat(new object[] { "select ChooseValue,ChooseUserName,ChooseUserCode from QuestUser  where DCID=", this.int_0, " and ItemID=", label2.Text.Trim() }), connection);
                    SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                    while (reader.Read())
                    {
                        if (this.labDCUser.Text.Trim().Replace("&nbsp;", "") == "")
                        {
                            label.Text = label.Text + "<tr height='20'><td>" + reader["ChooseValue"].ToString() + "</td><td width='150'><font color=red>(******)</font></td></tr>";
                            label.Text = label.Text + reader["ChooseValue"].ToString() + "<br>";
                        }
                        else
                        {
                            label.Text = label.Text + "<tr height='20'><td>" + reader["ChooseValue"].ToString() + "</td><td width='150'><font color=red>" + reader["ChooseUserName"].ToString() + "(" + reader["ChooseUserCode"].ToString() + ")</td></tr>";
                        }
                    }
                    reader.Close();
                    command.Dispose();
                    connection.Close();
                    connection.Dispose();
                    label.Text = label.Text + "</table>";
                }
                else
                {
                    string[] strArray2 = label5.Text.Trim().Split(new char[] { '#' });
                    label.Text = string.Empty;
                    for (int i = 0; i < strArray2.Length; i++)
                    {
                        if (strArray2[i].Trim() != "")
                        {
                            var currValue = this.method_3(values, label2.Text.Trim(), i.ToString(), label3.Text);
                            label.Text += "<div>";
                            label.Text += "<span>" + strArray2[i] + "</span>";
                            label.Text += "<div class=\"demo-slider\" countAttr=\"" + values + "\" valueAttr=\"" + currValue + "\"></div>";
                            label.Text += "<b>" + currValue + "票</b>";
                            label.Text += "</div>";

                            //label.Text = label.Text + "<tr height='20'><td>" + strArray2[i] + "</td><td width='150'><font color=red>(" + this.method_2(values, label2.Text.Trim(), i.ToString(), label3.Text) + ")</font></td></tr>";
                        }
                    }
                }
            }
        }

        private void method_0()
        {
            this.DataGridInfo.Visible = true;
            string selectCommandText = "select * from QuestItem where DCID=" + this.int_0;
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommandText, selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "OnlineQuest");
            this.DataGridInfo.DataSource = dataSet.Tables["OnlineQuest"].DefaultView;
            this.DataGridInfo.DataBind();
        }

        private void method_1()
        {
            string values = this.publicFun_0.GetValues(string.Concat(new object[] { "select ChooseTime from QuestUser where DCID=", this.int_0, " and ChooseUserCode='", this.httpCookie_0.Value, "'" }), "ChooseTime");
            string str2 = this.publicFun_0.GetValues("select ManagPoll from UserPower where UserCode='" + this.httpCookie_0.Value + "'", "ManagPoll");
            string str3 = "";
            string str4 = "";
            bool flag = false;
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand("select ID,TitleInfo,EndTime,DCUserCode,DCUserName,IsAnyUser,IsLook,IsIP,CreatUser,CreatTime,Status from OnlineQuest where ID=" + this.int_0, connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            if (reader.Read())
            {
                this.labTitleInfo.Text = reader["TitleInfo"].ToString();
                str3 = reader["CreatUser"].ToString();
                str4 = reader["IsAnyUser"].ToString();
                if (reader["IsLook"].ToString().Trim() == "Y")
                {
                    flag = true;
                }
                else if (!(reader["IsLook"].ToString().Trim() == "Z"))
                {
                    if (values != "")
                    {
                        flag = true;
                    }
                }
                else
                {
                    flag = false;
                }
            }
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
            if ((str2 == "Y") || (str3 == this.httpCookie_1.Value))
            {
                flag = true;
            }
            if (flag)
            {
                if (((str2 == "Y") || (str3 == this.httpCookie_1.Value)) && (str4 == "N"))
                {
                    this.labDCUser.Text = "<font color=blue>投票人员:</font>" + this.publicFun_0.GetValues("select DISTINCT ChooseUserName from QuestUser where DCID=" + this.int_0);
                }
                else
                {
                    this.labDCUser.Text = "";
                }
                this.method_0();
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('投票结果保密，您无权查看！');window.close();", true);
            }
        }

        private string method_2(string string_0, string string_1, string string_2, string string_3)
        {
            string values = "";
            if (!(string_3 == "Y"))
            {
                values = this.publicFun_0.GetValues(string.Concat(new object[] { "select count(*) as DCCount from QuestUser where DCID=", this.int_0, " and ItemID=", string_1, " and ChooseValue like'%#", string_2, "#%'" }), "DCCount");
                if (values.Trim() == "")
                {
                    values = "0";
                }
            }
            else
            {
                values = this.publicFun_0.GetValues(string.Concat(new object[] { "select count(*) as DCCount from QuestUser where DCID=", this.int_0, " and ItemID=", string_1, " and ChooseValue='", string_2, "'" }), "DCCount");
                if (values.Trim() == "")
                {
                    values = "0";
                }
            }
            double num = 0.0;
            if (string_0 == "0")
            {
                num = 0.0;
            }
            else
            {
                num = Convert.ToDouble(values) / Convert.ToDouble(string_0);
            }
            return ("共:" + values + "票 占" + num.ToString("0.00%"));
        }

        private string method_3(string string_0, string string_1, string string_2, string string_3)
        {
            string values = "";
            if (!(string_3 == "Y"))
            {
                values = this.publicFun_0.GetValues(string.Concat(new object[] { "select count(*) as DCCount from QuestUser where DCID=", this.int_0, " and ItemID=", string_1, " and ChooseValue like'%#", string_2, "#%'" }), "DCCount");
                if (values.Trim() == "")
                {
                    values = "0";
                }
            }
            else
            {
                values = this.publicFun_0.GetValues(string.Concat(new object[] { "select count(*) as DCCount from QuestUser where DCID=", this.int_0, " and ItemID=", string_1, " and ChooseValue='", string_2, "'" }), "DCCount");
                if (values.Trim() == "")
                {
                    values = "0";
                }
            }
            return values;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.int_0 = Convert.ToInt32(base.Request["ID"].ToString());
                base.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "---在线投票中心";
                if (!base.IsPostBack)
                {
                    if (this.publicFun_0.ReturnPaperData() != "Yes")
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')", true);
                    }
                    else
                    {
                        this.method_1();
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

